package com.task.submitter.controllers;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class BaseController {

	public String getEmail(HttpServletRequest request, HttpServletResponse response) throws IOException{
		UserService userService = UserServiceFactory.getUserService();
	    User user = userService.getCurrentUser();
	    if(user == null){
	    	response.sendRedirect(userService.createLoginURL(request.getRequestURI()));
	    }
	    String email = user != null ? user.getEmail() : "ANONYMOUS";
	    
	    return email;
	}
	
}
